<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>任务调度</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
    <div class="wrapper">

      <header class="main-header">
        <jsp:include page="header.jsp"></jsp:include>
      </header>
      <!-- Left side column. contains the logo and sidebar -->
      <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
          
          <jsp:include page="left-menu.jsp" />
        </section>
        <!-- /.sidebar -->
      </aside>

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>任务调度列表</h1>
        </section>
        <!-- Main content -->
        <section class="content">
          <div class="row">
            <div class="col-xs-12">
              <div class="box">
              
                <div class="col-xs-12">
                  <font size="2" color="red">如果想在异常日志里面记录被调URL的业务异常，请返回{"success":false,"errorMsg":"用户不能为空 test"}格式的消息,调度任务会根据你返回的 success 当 success 为 false 时，日志会记录errorMsg的信息，方便后面监控调度结果！</font>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                  <table id="joblist_table" class="table table-bordered table-hover">
                    <thead>
                      <tr>
                        <th style="width: 30%" data-field="aa">URL 地址</th>
                        <th style="width:  7%" data-field="bb">任务状态</th>
                         <th style="width: 7%" data-field="cc">请求方式</th>
                        <th style="width: 10%" data-field="dd">开始时间</th>
                        <th style="width: 10%" data-field="ee">上次执行时间</th>
                        <th style="width: 10%" data-field="ff">下次执行时间</th>
                        <th style="width: 11%" data-field="kk">任务描述</th>
                        <th style="width: 15%" data-field="gg">操作</th>
                      </tr>
                    </thead>
                    <tbody>
                    </tbody>
                    <tfoot>
                      <tr>
                        <th >
                        <button id="btn_addjob" type="button" class="btn btn-success btn-sm">新建任务 </button>    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
                        <label for="key_word">任务描述</label>&nbsp;&nbsp;
                        <input type="text" class="form-control" id="key_word" name="key_word"  placeholder="" required>
                        <button id="btn_query" type="button" class="btn btn-success btn-sm">查询任务 </button>
                        </th>
                      </tr>
                    </tfoot>
                      
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div><!-- /.col -->
          </div><!-- /.row -->
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
      <!-- 
      <footer class="main-footer">
        <div class="pull-right hidden-xs">
          <b>Version</b> 2.3.0
        </div>
      </footer>
      -->
      <!-- Control Sidebar -->
      <!-- Add the sidebar's background. This div must be placed  immediately after the control sidebar -->
      <div class="control-sidebar-bg"></div>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.4 -->
    <script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
    <!-- Bootstrap 3.3.5 -->
    <script src="bootstrap/js/bootstrap.min.js"></script>
    <!-- DataTables -->
    <script src="plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
    <script src="plugins/datatables/fnReloadAjax.js"></script>
    <!-- SlimScroll -->
    <script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
    <!-- FastClick -->
    <script src="plugins/fastclick/fastclick.min.js"></script>
    
    <script src="bootstrap/js/bootbox.min.js"></script>
    
    <!-- AdminLTE App -->
    <script src="dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>
    <!-- page script -->
    <script>
      var oTable = null;
      $(function () {
    	  oTable = $('#joblist_table').dataTable({
          "bAutoWidth":false,
          "bProcessing": true,
          "bServerSide": true,
          "bLengthChange":false,
          "bFilter":false,
          "bPaginate":true,
          destroy:true,
          "iDisplayLength":13,
          "pageLength":13,
          "bPaginationType": "simple_numbers",
          "sAjaxSource": "/task/getAllJobList3?q_key_word=",
	      "oLanguage": {
	          "sLengthMenu": "每页显示  _MENU_ 条记录",  
	          "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
	          "oPaginate": {
	              "sFirst": "首页",
	              "sPrevious": "前一页",
	              "sNext": "后一页",
	              "sLast": "尾页"
	              },
	          "sZeroRecords": "抱歉， 没有找到",
	          "sInfoEmpty": "没有数据"
	      }
        }); 
   	  $('#joblist_table tbody').on('click','tr',function(){
   	     var colIdx = oTable.row(this).index();
   	     //alert(oTable.row(colIdx).data()[0]);
   	     
   	     
   	     //bootbox.alert(oTable.row(colIdx).data()[0]);
   	 });
        $('#btn_addjob').on('click',function(){
        	$("#myModal").load('/task/toaddjob');
        	$('#myModal').modal({
        		keyboard: false
        	});
        });
        
        //btn_query
        $('#btn_query').on('click',function(){
        	
        	//init_oTable($('#key_word').val());
        	
        	//$('#joblist_table').DataTable().fnReloadAjax('/task/getAllJobList3?q_key_word=' + key_word);
        	//$('#joblist_table').dataTable().fnReloadAjax('/task/getAllJobList3?q_key_word=' + key_word);
        	//init_oTable(key_word);
        	
        	if(oTable){
        		 var oSettings = oTable.fnSettings();
                 oSettings.sAjaxSource = '/task/getAllJobList3?q_key_word=' + $('#key_word').val();//重新设置url
                 //Nothing will happen
                 oTable.fnReloadAjax(oSettings.sAjaxSource);
        	}
        	
        	
             
        });
        
      });
      
      function init_oTable(keys){
    	 $('#joblist_table').DataTable({
              "bAutoWidth":false,
              "bProcessing": true,
              "bServerSide": true,
              "bLengthChange":false,
              "bFilter":false,
              "bPaginate":true,
              "iDisplayLength":13,
              "pageLength":13,
              "bPaginationType": "simple_numbers",
              "sAjaxSource": "/task/getAllJobList3?q_key_word=" + keys,
    	      "oLanguage": {
    	          "sLengthMenu": "每页显示  _MENU_ 条记录",  
    	          "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
    	          "oPaginate": {
    	              "sFirst": "首页",
    	              "sPrevious": "前一页",
    	              "sNext": "后一页",
    	              "sLast": "尾页"
    	              },
    	          "sZeroRecords": "抱歉， 没有找到",
    	          "sInfoEmpty": "没有数据"
    	      }
            });
    	  
      }
      function fn_save_job(){
    	
    	  var _get_param = $("#addjobForm").serialize();
    	  closeMessage();
    	  $.ajax({
    		     type: 'POST',
    		     url: '/task/addjobcontroller?' +  _get_param,
    		     dataType: 'json',
    		     success: function(data){
    		    	  if(!data.success){
    		    		  $("#addjoberrormsgs").html(data.errorMsg);
    		    		  $("#error-block").removeClass("hide");  
    		    	  }else{
    		    		  $('#myModal').modal('hide');
    		    		  oTable.ajax.reload( null, false );
    		    		  
    		    	  }
    		     },
    		     error: function(data){}
    		     
    		});
      }
      function closeMessage(){
    	  $("#error-block").addClass("hide");
    	  $("#addjoberrormsgs").html("");
      }
      
      function showHelp(){
    	  
    	  var _hp = "";
    	  _hp = _hp + '每隔5秒执行一次：*/5 * * * * ?</br>';
    	  _hp = _hp + '每隔1分钟执行一次：0 */1 * * * ?</br>';
    	  _hp = _hp + '每天23点执行一次：0 0 23 * * ?</br>';
    	  _hp = _hp + '每天凌晨1点执行一次：0 0 1 * * ?</br>';
    	  _hp = _hp + '每月1号凌晨1点执行一次：0 0 1 1 * ?</br>';
    	  _hp = _hp + '每月最后一天23点执行一次：0 0 23 L * ?</br>';
    	  _hp = _hp + '每周星期天凌晨1点实行一次：0 0 1 ? * L</br>';
    	  _hp = _hp + '在26分、29分、33分执行一次：0 26,29,33 * * * ?</br>';
    	  _hp = _hp + '每天的0点、13点、18点、21点都执行一次：0 0 0,13,18,21 * * ?';
    	  
    	  bootbox.alert("样例：</br></br>" + _hp);
      }
      function fn_deletejob(jobName){
    	  bootbox.confirm("确认要删除 "+jobName+" 这个任务?", function(result) {
			  if(result){
				  $.ajax({
			 		     type: 'POST',
			 		     url: '/task/deleteJob?jobName=' + encodeContent(jobName),
			 		     dataType: 'json',
			 		     success: function(data){
			 		    	  if(!data.success){
			 		    		  //$("#addjoberrormsgs").html(data.errorMsg);
			 		    		  //$("#error-block").removeClass("hide");  
			 		    		  alert(data.errorMsg);
			 		    	  }else{
			 		    		  //$('#myModal').modal('hide');
			 		    		  oTable.ajax.reload( null, false );
			 		    		  
			 		    	  }
			 		     },
			 		     error: function(data){}
			 		});
			  }
		  });
    	  
      }
    
      //fn_resumejob
      
      function fn_resumejob(jobName){
    	  
    	  bootbox.confirm("确认要恢复 "+jobName+" 这个任务?", function(result) {
			  if(result){
				  $.ajax({
			 		     type: 'POST',
			 		     url: '/task/resumeJob?jobName=' + encodeContent(jobName),
			 		     dataType: 'json',
			 		     success: function(data){
			 		    	  if(!data.success){ 
			 		    		  alert(data.errorMsg);
			 		    	  }else{
			 		    		  oTable.ajax.reload( null, false );
			 		    		  
			 		    	  }
			 		     },
			 		     error: function(data){}
			 		});
			  }
		  }); 
    	  
      }
      
      function fn_toeditjob(jobName){
    	var url = '/task/toeditjob?jobName=' + encodeContent(jobName);
    	$("#myModal").load(url,new Object());
    	
      	$('#myModal').modal({
      		keyboard: false
      	});
    	  
      }
      //resumejob
      function fn_pausejob(jobName){
    	  bootbox.confirm("确认要暂停 "+jobName+" 这个任务?", function(result) {
			  if(result){
				  $.ajax({
			 		     type: 'POST',
			 		     url: '/task/pauseJob?jobName=' + encodeContent(jobName),
			 		     dataType: 'json',
			 		     success: function(data){
			 		    	  if(!data.success){ 
			 		    		  alert(data.errorMsg);
			 		    	  }else{
			 		    		  oTable.ajax.reload( null, false );
			 		    		  
			 		    	  }
			 		     },
			 		     error: function(data){}
			 		});
			  }
		  }); 
    	  
      }
      
      function encodeContent(data){ 
    	    return encodeURI(data).replace(/&/g,'%26').replace(/\+/g,'%2B').replace(/\s/g,'%20').replace(/#/g,'%23');  
     } 
      
      function fn_edit_job(){
    	  var _get_param = $("#addjobForm").serialize();
    	  closeMessage();
    	  $.ajax({
    		     type: 'POST',
    		     url: '/task/editjobcontroller?' +  _get_param,
    		     dataType: 'json',
    		     success: function(data){
    		    	  if(!data.success){
    		    		  $("#addjoberrormsgs").html(data.errorMsg);
    		    		  $("#error-block").removeClass("hide");  
    		    	  }else{
    		    		  $('#myModal').modal('hide');
    		    		  oTable.ajax.reload( null, false );
    		    		  
    		    	  }
    		     },
    		     error: function(data){}
    		});
    	  
      }
      
    </script>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div><!-- /.modal -->
</body>
</html>

